function [counts,bin_out] = logHist(data,bin_in,plotType,plotColor,lineStyle,lineWidth,fontSize)
% DESCRIPTION: Histogram with logarithmically-spaced bins
% USAGE:
%    logHist(data) - plots histogram of data on current axes using defualt 
%                    number of logarithmically-spaced bins 
%
%    logHist(data, N) - plots histogram of data on current axes using N 
%                       logarithmically-spaced bins 
%    
%    logHist(data,bins) - plots histogram of data on current axes using 
%                       bin centers specified in vector 'bins'
%
%    [counts,bins] = logHist() - same as above but returns counts and bin
%                              centers and does not plot result. 
%                              NOTE: use logBar to plot results
%
% Ira Thorpe - 9/28/07

error(nargchk(1, 6, nargin, 'struct'))                              
if nargin < 7 || sum(size(fontSize)) == 0, fontSize = 16; end
if nargin < 6 || sum(size(lineWidth)) == 0, lineWidth = 2; end
if nargin < 5 || sum(size(lineStyle)) == 0, lineStyle = '-'; end
if nargin < 4 || sum(size(plotColor)) == 0, plotColor = 'r'; end
if nargin < 3 || sum(size(plotType)) == 0, plotType = 'line'; end 
if nargin < 2 || sum(size(bin_in)) == 0, bin_in = 20; end   % use 20 bins by default

% Set up bin centers
if max(size(bin_in)) > 1  % bins are specificed by user
    Nbins = max(size(bin_in));
    bin_out = bin_in;
else % need to compute bins
    Nbins = bin_in;
    bin_out = logspace(floor(log10(min(data))),ceil(log10(max(data))), Nbins);
end  

clear bin_in

% Determine bin edges
edges(1) = -inf;
for i = 2:Nbins
    edges(i) = 10^((1/2)*(log10(bin_out(i-1))+log10(bin_out(i))));
end 
edges(Nbins+1) = inf; 
     
counts = histc(data,edges);    
counts(Nbins+1) = [];

if nargout == 0
    logBar(bin_out,counts,plotType,plotColor,lineStyle,lineWidth,fontSize);
end
 
 
     